<template>
  <div class="divBox trans">
    <el-card class="box-card">
      <div slot="header" class="clearfix">
        <div class="container">
          <el-form size="small" inline label-width="150px">
            <el-form-item
              :label="$t('timeselection')"
              class="width100 is_Scroll"
              style="display: block"
            >
              <el-radio-group
                v-model="tableFrom.date"
                type="button"
                class="mr20 "
                size="small"
                @change="selectChange(tableFrom.date)"
              >
                <el-radio-button
                  v-for="(item, i) in fromList.fromTxt"
                  :key="i"
                  :label="item.val"
                  >{{ item.text }}</el-radio-button
                >
              </el-radio-group>
              <el-date-picker
                v-model="timeVal"
                value-format="yyyy/MM/dd"
                format="yyyy/MM/dd"
                size="small"
                type="daterange"
                placement="bottom-end"
                :placeholder="$t('customtime')"
                style="width: 250px"
                @change="onchangeTime"
              />
            </el-form-item>
            <el-form-item :label="$t('auditstatus')">
              <el-radio-group
                v-model="tableFrom.status"
                type="button"
                @change="getList(1)"
              >
                <el-radio-button label="">{{ $t("all") }} </el-radio-button>
                <el-radio-button label="0">{{
                  $t("tobereviewed")
                }}</el-radio-button>
                <el-radio-button label="1">{{
                  $t("reviewed")
                }}</el-radio-button>
                <el-radio-button label="-1">{{
                  $t("auditfailed")
                }}</el-radio-button>
              </el-radio-group>
            </el-form-item>
            <el-form-item :label="$t('arrivalstatus')">
              <el-select
                v-model="tableFrom.financial_status"
                :placeholder="$t('pleaseselect')"
                class="filter-item selWidth mr20"
                clearable
                @change="getList(1)"
              >
                <el-option
                  v-for="item in arrivalStatusList"
                  :key="item.value"
                  :label="item.label"
                  :value="item.value"
                />
              </el-select>
            </el-form-item>
            <br />
            <el-form-item :label="$t('paymentmethod')">
              <el-radio-group
                v-model="tableFrom.financial_type"
                type="button"
                @change="getList(1)"
              >
                <el-radio-button label="">{{ $t("all") }} </el-radio-button>
                <el-radio-button label="1">USDT</el-radio-button>
                <el-radio-button label="3">{{
                  $t("bankcard")
                }}</el-radio-button>
              </el-radio-group>
            </el-form-item>
            <el-form-item :label="$t('keywords')" class="width100 is_Scroll">
              <el-input
                v-model="tableFrom.keyword"
                @keyup.enter.native="getList(1)"
                :placeholder="$t('please18')"
                class="selWidth"
                size="small"
              >
                <el-button
                  slot="append"
                  icon="el-icon-search"
                  size="small"
                  class="el-button-solt"
                  @click="getList(1)"
                />
              </el-input>
              <el-button
                size="small"
                type="primary"
                icon="el-icon-top"
                @click="exportRecord"
                >{{ $t("listexport") }}</el-button
              >
              <el-button
                size="small"
                type="primary"
                @click="getExportFileList"
                >{{ $t("exportrecords") }}</el-button
              >
            </el-form-item>
            <el-button
              style="display: block"
              size="small"
              type="primary"
              @click="applyTransfer"
            >
              {{ $t("applyfortransfer") }}
            </el-button>
          </el-form>
        </div>
        <cards-data :card-lists="cardLists" />
      </div>
      <el-table
        v-loading="listLoading"
        tooltip-effect="dark"
        :data="tableData.data"
        style="width: 100%"
        class="table"
      >
        <el-table-column :label="$t('serialno')" min-width="60">
          <template slot-scope="scope">
            <span>{{
              scope.$index + (tableFrom.page - 1) * tableFrom.limit + 1
            }}</span>
          </template>
        </el-table-column>
        <el-table-column
          prop="create_time"
          :label="$t('applicationtime')"
          min-width="170"
        />
        <el-table-column
          prop="extract_money"
          :label="$t('transferamount(yuan)')"
          min-width="120"
        />
        <el-table-column
          prop="mer_admin_id"
          :label="$t('administratorname')"
          min-width="90"
        />
        <el-table-column :label="$t('paymentmethod')" min-width="100">
          <template slot-scope="scope">
            <span v-if="scope.row.financial_type">{{
              scope.row.financial_type == 1
                ? "USDT"
                : scope.row.financial_type == 2
                ? $t("wechat")
                : $t("bankcard")
            }}</span>
            <span v-else>--</span>
          </template>
        </el-table-column>

        <el-table-column :label="$t('auditstatus')" min-width="120">
          <template slot-scope="scope">
            <span>{{
              scope.row.status == 0
                ? $t("tobereviewed")
                : scope.row.status == 1
                ? $t("approved")
                : $t("approvalfailed")
            }}</span>
            <span v-if="scope.row.status === -1" style="font-size: 12px">
              <br />
              {{ $t("reason") }}：{{ scope.row.refusal }}
            </span>
          </template>
        </el-table-column>
        <el-table-column :label="$t('arrivalstatus')" min-width="120">
          <template slot-scope="scope">
            <span>{{
              scope.row.financial_status == 1
                ? $t("received")
                : $t("unreceived")
            }}</span>
          </template>
        </el-table-column>
        <el-table-column
          prop="mer_money"
          :label="$t('balance(yuan)')"
          min-width="120"
        />
        <el-table-column
          :label="$t('operation')"
          min-width="130"
          fixed="right"
          align="center"
        >
          <template slot-scope="scope">
            <el-button
              type="text"
              size="small"
              @click="transferDetail(scope.row.financial_id)"
              >{{ $t("transferinformation") }}</el-button
            >
            <el-button
              type="text"
              size="small"
              @click="transferMark(scope.row.financial_id)"
              >{{ $t("remarks") }}</el-button
            >
          </template>
        </el-table-column>
      </el-table>
      <div class="block">
        <el-pagination
          :page-sizes="[20, 40, 60, 80]"
          :page-size="tableFrom.limit"
          :current-page="tableFrom.page"
          layout="total, sizes, prev, pager, next, jumper"
          :total="tableData.total"
          @size-change="handleSizeChange"
          @current-change="pageChange"
        />
      </div>
    </el-card>
    <!--转账信息-->
    <el-dialog
      v-if="dialogVisible"
      :title="$t('transferinformation')"
      :visible.sync="dialogVisible"
      width="700px"
    >
      <div class="box-container">
        <div class="acea-row">
          <div class="list sp100">
            <label class="name">{{ $t("merchantbalance") }}：</label
            >{{ transferData.mer_money }}
          </div>
          <div class="list sp100">
            <label class="name">{{ $t("paymentmethod") }}：</label
            >{{
              transferData.financial_type == 1
                ? "USDT"
                : transferData.financial_type == 2
                ? $t("wechat")
                : $t("bankcard")
            }}
          </div>
          <div v-if="transferData.financial_type == 1" class="list sp100">
            <label class="name">USDT主网络：</label
            >{{ transferData.financial_account.bank }}
          </div>
          <div v-if="transferData.financial_type == 1" class="list sp100">
            <label class="name">{{ $t("rechargeaddress") }}：</label
            >{{ transferData.financial_account.bank_code }}
          </div>
          <div v-if="transferData.financial_type == 1" class="list sp100">
            <label class="name">{{ $t("accountname") }}：</label
            >{{ transferData.financial_account.name }}
          </div>
          <div v-if="transferData.financial_type != 1" class="list sp100">
            <label class="name">{{ $t("bankofdeposit") }}：</label
            >{{ transferData.financial_account.name }}
          </div>
          <div v-if="transferData.financial_type == 2" class="list sp100">
            <label class="name">{{ $t("wechatnumber") }}：</label
            >{{ transferData.financial_account.wechat }}
          </div>
          <div v-if="transferData.financial_type == 2" class="list sp100 image">
            <label class="name">{{ $t("wechatcollectionqrcode") }}：</label
            ><img
              style="max-width: 150px; height: 80px"
              :src="transferData.financial_account.wechat_code"
            />
          </div>
          <div v-if="transferData.financial_type == 3" class="list sp100">
            <label class="name">{{ $t("bankcardaccountnumber") }}：</label
            >{{ transferData.financial_account.alipay }}
          </div>
          <div v-if="transferData.financial_type == 3" class="list sp100">
            <label class="name">{{ $t("accountname") }}：</label
            >{{ transferData.financial_account.alipay_code }}
          </div>
          <div class="list sp100">
            <label class="name">{{ $t("transfppliedfothistime") }}：</label
            ><span class="font-red">{{ transferData.extract_money }}</span>
          </div>
          <div class="list sp100">
            <label class="name">{{ $t("actualamountreceived") }}：</label
            ><span class="font-red">{{ transferData.real_money }}</span>
          </div>
          <div class="list sp100">
            <label class="name">{{ $t("auditstatus") }}</label
            >{{
              transferData.status == 0
                ? $t("tobereviewed")
                : transferData.status == 1
                ? $t("reviewed")
                : $t("auditfailed")
            }}
          </div>
          <div v-if="transferData.status == 1" class="list sp100">
            <label class="name">审核时间：</label>{{ transferData.status_time }}
          </div>
          <div
            v-if="transferData.status == 1 && transferData.update_time"
            class="list sp100"
          >
            <label class="name">转账凭证：</label>
            <div v-if="transferData.image.length > 0" class="acea-row">
              <div
                v-for="(item, index) in transferData.image"
                :key="index"
                class="pictrue"
              >
                <img @click="getPicture(item)" :src="item" />
              </div>
            </div>
          </div>
          <div
            v-if="transferData.status == 1 && transferData.update_time"
            class="list sp100"
          >
            <label class="name">{{ $t("transfertime") }}：</label
            >{{ transferData.update_time }}
          </div>
          <div v-if="transferData.status == -1" class="list sp100">
            <label class="name">{{ $t("reasonforfailure") }}：</label
            >{{ transferData.refusal }}
          </div>
        </div>
      </div>
    </el-dialog>
    <!--查看二维码-->
    <el-dialog
      v-if="pictureVisible"
      :visible.sync="pictureVisible"
      width="700px"
    >
      <img :src="pictureUrl" class="pictures" />
    </el-dialog>
    <!--导出订单列表-->
    <file-list ref="exportList" />
  </div>
</template>
<script>
// +----------------------------------------------------------------------
// | CRMEB [ CRMEB赋能开发者，助力企业发展 ]
// +----------------------------------------------------------------------
// | Copyright (c) 2016~2021 https://www.crmeb.com All rights reserved.
// +----------------------------------------------------------------------
// | Licensed CRMEB并不是自由软件，未经许可不能去掉CRMEB相关版权
// +----------------------------------------------------------------------
// | Author: CRMEB Team <admin@crmeb.com>
// +----------------------------------------------------------------------
import {
  transferLstApi,
  applyTransferApi,
  transferDetailApi,
  transferMarkApi,
  transferRecordsExportApi
} from "@/api/accounts";
import cardsData from "@/components/cards/index";
import fileList from "@/components/exportFile/fileList";
export default {
  components: { cardsData, fileList },
  name: "transferAccount",
  data() {
    return {
      tableData: {
        data: [],
        total: 0
      },
      arrivalStatusList: [
        { label: this.$t("received"), value: 1 },
        { label: this.$t("unreceived"), value: 0 }
      ],
      listLoading: true,
      tableFrom: {
        date: "",
        page: 1,
        limit: 20,
        keyword: "",
        financial_type: "",
        status: "",
        financial_status: ""
      },
      timeVal: [],
      fromList: {
        title: this.$t("selectionperiod"),
        custom: true,
        fromTxt: [
          { text: this.$t("all"), val: "" },
          { text: this.$t("today"), val: "today" },
          { text: this.$t("yesterday"), val: "yesterday" },
          { text: this.$t("last7days"), val: "lately7" },
          { text: this.$t("last30days"), val: "lately30" },
          { text: this.$t("thismonth"), val: "month" },
          { text: this.$t("thisyear"), val: "year" }
        ]
      },
      selectionList: [],
      loading: false,
      dialogVisible: false,
      pictureVisible: false,
      pictureUrl: "",
      transferData: {},
      cardLists: []
    };
  },
  mounted() {
    this.getList(1);
  },
  methods: {
    // 转账信息
    transferDetail(id) {
      transferDetailApi(id)
        .then(res => {
          this.dialogVisible = true;
          this.transferData = res.data;
        })
        .catch(res => {
          this.$message.error(res.message);
        });
    },
    // 获取支付二维码
    getPicture(url) {
      this.pictureVisible = true;
      this.pictureUrl = url;
    },
    // 备注
    transferMark(id) {
      this.$modalForm(transferMarkApi(id)).then(() => this.getList(1));
    },
    // 申请转账
    applyTransfer() {
      this.$modalForm(applyTransferApi()).then(() => this.getList(1));
    },
    // 选择时间
    selectChange(tab) {
      this.tableFrom.date = tab;
      this.timeVal = [];
      this.getList(1);
    },
    // 具体日期
    onchangeTime(e) {
      this.timeVal = e;
      this.tableFrom.date = e ? this.timeVal.join("-") : "";
      this.getList(1);
    },
    // 导出
    exportRecord() {
      transferRecordsExportApi(this.tableFrom)
        .then(res => {
          const h = this.$createElement;
          this.$msgbox({
            title: this.$t("tips"),
            message: h("p", null, [
              h("span", null, this.$t("please71")),
              h("span", { style: "color: teal" }, this.$t("exportrecords")),
              h("span", null, this.$t("see"))
            ]),
            confirmButtonText: this.$t("igotit")
          }).then(action => {});
        })
        .catch(res => {
          this.$message.error(res.message);
        });
    },
    // 导出列表
    getExportFileList() {
      this.$refs.exportList.exportFileList();
    },
    // 列表
    getList(num) {
      this.listLoading = true;
      this.tableFrom.page = num ? num : this.tableFrom.page;
      transferLstApi(this.tableFrom)
        .then(res => {
          this.tableData.data = res.data.list;
          this.tableData.total = res.data.count;
          this.listLoading = false;
        })
        .catch(res => {
          this.$message.error(res.message);
          this.listLoading = false;
        });
    },
    pageChange(page) {
      this.tableFrom.page = page;
      this.getList("");
    },
    handleSizeChange(val) {
      this.tableFrom.limit = val;
      this.getList("");
    },

    handleClose() {
      this.dialogLogistics = false;
    }
  }
};
</script>

<style lang="scss" scoped>
::v-deep .el-dialog__title {
  font-weight: bold;
}
.selWidth {
  width: 300px;
}
.el-dropdown-link {
  cursor: pointer;
  color: #409eff;
  font-size: 12px;
}
.el-icon-arrow-down {
  font-size: 12px;
}
.font-red {
  color: #ff4949;
}
.tabBox_tit {
  width: 60%;
  font-size: 12px !important;
  margin: 0 2px 0 10px;
  letter-spacing: 1px;
  padding: 5px 0;
  box-sizing: border-box;
}
.pictrue {
  width: 60px;
  height: 60px;
  border: 1px dotted rgba(0, 0, 0, 0.1);
  margin-right: 10px;
  position: relative;
  cursor: pointer;
  img {
    width: 100%;
    height: 100%;
  }
}
.box-container {
  overflow: hidden;
  padding: 0 10px;
}

.box-container .list.image {
  margin: 20px 0;
  position: relative;
}
.box-container .list.image img {
  position: absolute;
  top: -20px;
}
.box-container .list {
  float: left;
  line-height: 40px;
}
.box-container .sp100 {
  width: 100%;
}

.acea-row {
  margin-bottom: 25px;
}
</style>
